package org.corey.voxiverse.layers;

import java.util.Random;

import org.corey.voxiverse.Block;
import org.corey.voxiverse.Block.BlockType;

public class BasicGen {
	public BasicGen(){
		
	}
	
	public static void Generate(Block[][][] Blocks, int CHUNK_SIZE, Random r){
		for (int x = 0; x < CHUNK_SIZE;x++){
			for (int z = 0; z < CHUNK_SIZE; z++){
					
				for (int y = 0; y < CHUNK_SIZE; y++){
					
					Blocks[x][y][z] = new Block(BlockType.BlockType_Default); //first fill every block with an unrendered air block

				}
				
				
				for (int y = 0; y < 6; y++){
					if (y == 2) {
						Blocks[x][y][z] = new Block(BlockType.BlockType_Bedrock);
					}
					
					if (y >= 3 && !(y > 4)) {
						if (r.nextFloat()>0.4f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Bedrock);
						}
					}
					
					else {
						if (r.nextFloat()>0.9f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Bedrock);
						}
					}
					
					
					
				}
				
				for (int y = 4; y < 45; y++){
					if (y >= 2 && !(y > 30)){
						if (r.nextFloat()>0.05f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Stone);
						}
					}
					else {
						if (r.nextFloat()>0.3f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Stone);
						}
					}
				}
				
				for (int y = 4; y < 55; y++){
					if (y >= 2 && !(y > 25)){
						if (r.nextFloat()>0.99f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Sand);
						}
					}
					
					if (y >= 25 && !(y > 40)){
						if (r.nextFloat()>0.96f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Sand);
						}
					}
					
					else{
						if (r.nextFloat()>0.94f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Sand);
						}
					}
					
				}
				
				for (int y = 40; y < 55; y++){
					if (y >= 40 && !(y > 42)){
						if (r.nextFloat()>0.8f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Dirt);
						}
					}
					
					else {
						if (r.nextFloat()>0.4f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Dirt);
						}
					}
				}
				
				for (int y = 50; y < CHUNK_SIZE; y++){
					if (Blocks[x][y-1][z].GetID() == 2 && Blocks[x][y][z].GetID() == 0){
						Blocks[x][y][z] = new Block(BlockType.BlockType_Grass);
					}
				}
				
				for (int y = 50; y < 56; y++){
					if (Blocks[x][y][z].GetID() == 0){
						if (r.nextFloat()>0.999f){
							Blocks[x][y][z] = new Block(BlockType.BlockType_Water);
						}
							WaterGen.Generate(Blocks, CHUNK_SIZE, r, x, y, z);
					}
				}
				
			}
		}
	}
}
